package com.vinoxm.common.core.configure;

import com.vinoxm.common.core.interceptor.CustomHandlerInterceptor;
import lombok.Setter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.List;

public class GlobalWebConfigure implements WebMvcConfigurer {

    @Setter(onMethod_ = {@Resource})
    private List<CustomHandlerInterceptor> interceptors;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        for (CustomHandlerInterceptor interceptor : interceptors) {
            registry.addInterceptor(interceptor).addPathPatterns(interceptor.getPathPatterns());
        }
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**");
    }
}
